package com.bootdo.common.task;

import cn.hutool.core.util.IdUtil;
import com.bootdo.common.utils.DateUtils;
import com.bootdo.system.domain.CheckLogDO;
import com.bootdo.system.domain.SafeItemDO;
import com.bootdo.system.service.CheckLogService;
import com.bootdo.system.service.SafeItemService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhouxm
 */
public class SafeCheckTask implements Job {
    @Autowired
    private SafeItemService safeItemService;

    @Autowired
    private CheckLogService checkLogService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("delFlag","2");
        List<SafeItemDO> safeItemList = safeItemService.list(map);
        if (!(CollectionUtils.isEmpty(safeItemList))) {
            for (SafeItemDO item : safeItemList) {
                CheckLogDO logDO = new CheckLogDO();
                logDO.setId(IdUtil.fastSimpleUUID());
                logDO.setSafeId(item.getItemId());
                logDO.setStatus("0");
                logDO.setCreateTime(new Date());
                logDO.setCheckTimeStart(DateUtils.getFirstDay());
                logDO.setCheckTimeEnd(DateUtils.getLastDay());
                logDO.setAttachId(IdUtil.fastSimpleUUID());
                checkLogService.save(logDO);
            }
        }
    }
}
